package com.shangyueshang.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author JokeyFeng
 * @date: 2022/1/4 23:16
 * @project: shangyueshang
 * @package: com.shangyueshang.config
 * @comment: 跨域配置
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
	
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		//运行跨域访问的路径
		registry.addMapping("/**")
				//允许跨域访问的源
				.allowedOriginPatterns("*")
				//允许请求方法
				.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
				//预检间隔时间
				.maxAge(16800)
				//允许头部设置
				.allowedHeaders("*")
				//是否发送cookie
				.allowCredentials(true);
	}
}
